Ext.define('PJ.view.studentfeedbackccccp.List', {
    extend: 'AM.default.DefaultList',
    requires: ['AM.default.DefaultSearchForm', 
               'AM.default.DateTime', 
               'AM.default.DefaultDateField'
               ],
    initComponent: function(){
    	var me = this;
        me.columns = [{
    		header: '培训班编号',
    		dataIndex: 't.classNum',
    		width: 120,
    		renderer: function(value, meta, record){
    			meta.style = "white-space:normal;cursor: pointer;color:blue;";
    			meta.tdAttr = "data-qtip='" + value + "' classId=" + record.get("classId");
    			return value;
    		},
    		listeners: {
    			click: function(g, clm){
    				var classId = clm.getAttribute("classId");
    				win = Ext.create('PJ.view.trainingmanagement.Edit', {
    					title: "查看培训班",
    					flag:4,
    					grid: me,
    					isDisable:false,
    					isReadOnly:true,
    					classId:classId,
    					isHideExpectTime: false
    				}).show();
    				var actionName = "load";
    				if(gj_onlineLearning_constant.loadType == "jsonp"){
    					actionName = "loadJsonp";
    				}
    				win.down("form").getForm().doAction(actionName,{
    					url:me.store.preUpdateUrl,
    					params:{
    						classId: classId
    					},
    					success:function(f,action){
    						var data = action.response.responseText;
    	        			var json = gj_onlineLearning_constant.loadType=="ajax" ? Ext.decode(data, true) : action.response;
    	        			var form = win.down('form');	 
    	        			var baseForm = form.getForm();
    	        			baseForm.findField("classNum").setValue(json.data.classNum);
    	        			baseForm.findField("classNum_").setValue(json.data.classNum);
    					}
    				});

    			}
    		}
    	}, {
            header: '培训班名称',
            dataIndex: 't.className',
            flex: 1,
            minWidth: 120,
    		renderer: function(value, metaData, record){
    			metaData.tdAttr = 'data-qtip="' + value + '"';
    			return value;
    		}
        },{
            header: '开班时间',
            dataIndex: 't.beginDate',
            width: 80 
        }, {
            header: '结业时间',
            dataIndex: 't.endDate',
            width: 80 
        }, {
            header: '已报人数',
            dataIndex: 'reportedNum',
            width: 110,
            sortable: false,
            renderer: function(value, metaData, record){
            	return value ;
            }
        }, {
            header: '班级状态',
            dataIndex: 't.openState',
            renderer: function(v, metaData, record){
            	if(record.get("t.publishState") == 2){
            		return '未开班';
            	}else{
            		if (v == 3) {
                        return '<span style="color:red;">' + '已结班' + '</span>';
                    }
                    else if(v == 1) {
                        return '<span style="color:green;">' + '已开班' + '</span>';
                    }
                    else if(v == 2) {
                        return '未开班';
                    }
            	}
            },
            width: 70
        }];
        me.store = Ext.create('PJ.'+ prototype +'.studentfeedbackministries.List', {
            isLoad: false
        });
        this.loadType = gj_onlineLearning_constant.loadType;//加载方式
        me.callParent(arguments);
    },
    //评价
    onStudentEvaluate:function(){
    	var me = this;
    	var records = me.getSelectionModel().getSelection();
    	if(records.length > 1){
            Ext.Msg.show({
                title: '提示',
                msg: '只允许操作一条数据！',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
    		return;
    	}
    	win = Ext.create('PJ.view.studentfeedbackccccp.ViewFeedbackFrame',{
    		title: "解锁学员评价",
    		grid: me,
    		classId:records[0].get("classId"),
    		className:records[0].get("t.className"),
    		ministrieName:records[0].get("t.ministrieName"),
    		beginDate: records[0].get("t.beginDate"),
    		endDate: records[0].get("t.endDate"),
    		openState: records[0].get("t.openState")
    	}).show();
    	var actionName = "load";//默认使用非JSONP的加载方法名“load”
        if(gj_onlineLearning_constant.loadType=="jsonp") {
        	actionName= "loadJsonp";
        }
        win.down('form').getForm().doAction(actionName,{
        	url: me.store.configurationUrl,
            params: {
            	classId: records[0].get("classId")//培训班ID
            },
            success:function(form,action){
            	var data = action.response.responseText;
    			var json = gj_onlineLearning_constant.loadType=="ajax" ? Ext.decode(data, true) : action.response;
    			var dateStar = json.data.beginDateStr;//举办时间（开始）
    			var dateEnd = json.data.endDateStr;//举办时间（截止）
    			var form = win.down('form');	 
    			var baseForm = form.getForm();
    			baseForm.findField("classMainName").setValue(json.data.className);//班级名称
    			baseForm.findField("trainingDeptName").setValue(json.data.ministrieName);//委托部委
    			baseForm.findField("learnTime").setValue(dateStar + ' 至 ' + dateEnd);
            }
        });
    },
    listeners: {
    	selectionchange: function(selModel, selected){
            this.down('#' + this.oldId + "Evaluate").setDisabled(selected.length === 0);
        },
    	viewready: function(){
    		var me = this;
    		me.addDocked([{
    			dock: 'top',
    			xtype: "searchform",
    			columnCount: 3,
    			fieldDefaults: {
    				labelAlign: 'right',
    				labelWidth: 70
    			},
    			items: [{
    				xtype: "textfield",
    				fieldLabel: '培训班编号',
    				name: "searchTrainingNum",
    				maxLength: "50",
    				emptyText: "请输入培训班编号"
    			}, {
    				xtype: "textfield",
    				fieldLabel: '培训班名称',
    				name: "searchClassName",
    				maxLength: "20",
    				emptyText: "请输入培训班问卷名称",
    				labelWidth: 90
    			}, {
    				xtype: 'defaultDate',
    				fieldLabel: '开班时间',
    				name: 'searchBeginDate',
    				emptyText: "请输入开班时间"
    			},{
					xtype: "combo",
					fieldLabel: '班级状态',
					name: "searchOpenState",
					store: Ext.create("Ext.data.ArrayStore", {
						fields: ['value', 'text'],
						data: [[1, '已开班'],[2,'未开班'],[3,'已结班']]
					}),
					valueField: 'value',
					displayField: 'text',
					editable: false,
					emptyText: "请选择"
				}],
    			grid: this
    		}, {
                xtype: 'toolbar',
                dock: 'top',
                displayInfo: true,
                items: [{
                    text: '解锁学员评价',
                    iconCls: 'keyStudentIco',
                    itemId: this.oldId + "Evaluate",
                    disabled: true,
                    scope: this,
                    handler: this.onStudentEvaluate
                }, "->", this.countSelectPanel]
            }]);
            var store = this.store;
            var params = store.proxy.extraParams;
            var newParams = {};
            Ext.apply(params, newParams);
            store.isLoad = true;
            store.load();
    		// 触发权限过滤事件
    		this.fireEvent("permission", this);
    	}
    }
});
